package com.jiazhong.shixi_bookstore.controller;

import com.jiazhong.shixi_bookstore.bean.User;
import com.jiazhong.shixi_bookstore.mapper.UserMapper;
import com.jiazhong.shixi_bookstore.utll.JsonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")

public class UserController {
    @Resource
    private UserMapper userMapper;

    @RequestMapping("/login")
    public JsonResult login(User user){
        User u = userMapper.login(user);
        if(u==null){
            JsonResult result = new JsonResult(false,500,null,"账号或者密码错误");
            return result;
        }
        else{
            JsonResult result = new JsonResult(true,200,u.getId(),"");
            return result;
        }
    }

    @RequestMapping("/add")
    public JsonResult add(User user){
        System.out.println(user);
        userMapper.add(user);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }
}
